using System;
using System.Diagnostics;
using System.Threading;
using UnityEngine;

namespace Assets.Scripts.GDK
{
	public class gdk_threadDownLoad
	{
		private static gdk_threadDownLoad _instance;

		private bool isStop;

		private Thread thread;

		private const int ReadWriteTimeOut = 2000;

		private const int TimeOutWait = 5000;

		public static gdk_threadDownLoad Instance
		{
			get
			{
				if (_instance == null)
				{
					_instance = new gdk_threadDownLoad();
				}
				return _instance;
			}
			set
			{
				_instance = value;
			}
		}

		public float progress
		{
			get;
			private set;
		}

		public bool isDone
		{
			get;
			private set;
		}

		public void DownLoad(Action callBack, System.Threading.ThreadPriority threadPriority = System.Threading.ThreadPriority.Normal)
		{
			isStop = false;
			Stopwatch stopWatch = new Stopwatch();
			thread = new Thread((ThreadStart)delegate
			{
				stopWatch.Start();
				stopWatch.Stop();
				UnityEngine.Debug.Log("耗时: " + stopWatch.ElapsedMilliseconds);
				if (progress == 1f)
				{
					isDone = true;
					if (callBack != null)
					{
						callBack();
					}
					thread.Abort();
				}
			});
			thread.IsBackground = true;
			thread.Priority = threadPriority;
			thread.Start();
		}

		public void Close()
		{
			isStop = true;
		}
	}
}
